{extend name="base" /}
{block name="body"}
<div class="layui-card">
	<div class="layui-card-header">
		<form action="{:url('admin/resourcereview/index')}" class="layui-form" method="get">
			<div class="layui-form-item">
				<div class="layui-inline">
					用户
				</div>
				<div class="layui-inline">
					<input type="text" name="name" placeholder="请输入学者/手机" value="{:input('name')}" autocomplete="off" class="layui-input"/>
				</div>
				<div class="layui-inline">
					成果类型
				</div>
				<div class="layui-inline">
					<select name="resource_code" id="resource_code"  >
						<option value="">全部成果</option>
						<option value="J">中文论文</option>
						<option value="I">SCI</option>
						<option value="E">EI</option>
						<option value="P">专利</option>
						<option value="O">成果</option>
					</select>
				</div>
				<div class="layui-inline">
					成果状态
				</div>
				<div class="layui-inline">
					<select name="status" id="status" >
						<option value="">全部状态</option>
						<option value="0">待审核</option>
						<option value="-1">已拒绝</option>
						<option value="1">已审核</option>
						<!-- (-1-已拒绝0-待审核1-已审核) -->
					</select>
				</div>
				<div class="layui-inline">
					<button class="layui-btn layui-btn-normal ajax-search"><i class="fa fa-search"></i>查询学者</button>
					<!-- <a onclick="add()" class="layui-btn"><i class="fa fa-plus-circle"></i> 添加学者</a> -->
				</div>
			</div>
		</form>
	</div>
	<div class="layui-card-body">
		<table class="layui-table layui-form">
			<thead>
			<tr>
				<!-- 姓名 机构 手机号 成果类型 标题 年份 作者 -->
				<th>姓名</th>
				<th>机构</th>
				<th>手机号</th>
				<th>成果类型</th>
				<th>标题</th>
				<th>年份</th>
				<th>作者</th>
				<th>状态</th>
				<th>操作</th>
			</tr>
			</thead>
			<tbody>
			
			{foreach name="list" item="v" empty="$empty"}
			<tr>
				<td>{$v.scholar_name}</td>
				<td>{$v.institute}</td>
				<td>{$v.phone}</td>

				<!-- 
				<th>中文论文 J</th>
				<th>SCI I</th>
				<th>EI </th>
				<th>专利 U</th>
				<th>其他 other</th> -->

				<td align="center">
					<!-- J 期刊   B 图书   C 会议   S 标准   D 学位论文   P 专利   R 报告   Q 其他   A 成果   O 项目   I SCI  E EI    U SCOPUS   T 团队   Y 活动 -->
					<!-- fusion_data_warehouse -->
					{if condition="$v.resource_code == 'J'"}中文论文
					{elseif condition="$v.resource_code == 'I'"}SCI
					{elseif condition="$v.resource_code == 'E'"}EI
					{elseif condition="$v.resource_code == 'P'"}专利
					{elseif condition="$v.resource_code == 'O'"}成果
					{else/}
						其他
					{/if}
					<!-- {$v.resource_code} -->
				</td>
				<td>{$v.title}</td>
				<td>{$v.year}</td>
				<td>{$v.creatorAll}</td>
				<td>

					{$v.status == 1?'已审核':($v.status == 0?'待审核':'已拒绝')}

				</td>
				<td>
					{if condition="$v.status != 1"}
					<a onclick="edit({$v.id})" class="layui-btn layui-btn-sm layui-btn-normal"><i class="fa fa-delete"></i>审核</a>
					{/if}
				</td>
			</tr>
			{/foreach}
			</tbody>
		</table>
		<div class="page">{$list->render()}</div>
	</div>
</div>
{/block}
{block name="js"}
<style>
	.my-btn .layui-layer-btn .layui-layer-btn0 {
		border: 1px solid #dedede!important;
		background-color:  #dedede!important;
		color: #333;
	}
	.my-btn .layui-layer-btn .layui-layer-btn1 {
		border: 1px solid #1E9FFF!important;
		background-color:  #1E9FFF!important;
		color: #fff;
	}
</style>
<script>
	console.log("{:input('name')}")
	console.log("{:input('status')}")
	console.log("{:input('resource_code')}")
	// JSON.stringify
	//iframe 层
	layui.use(['form'], function () {
		var form = layui.form;
		$(function(){
			$('#status').val("{:input('status')}")
			$('#resource_code').val("{:input('resource_code')}")
			form.render()
		})
	})

	function edit(id){
		layer.confirm('是否审核该成果?', {
			time: 0,
			icon: 3,
			shade: 0.2,
			title:'提示',
			closeBtn: 1,
			skin:'my-btn',
			btn: [ '拒绝' ,'审核通过',],},function(index){
				layer.close(index);
				$.ajax({
					url: '/admin/resourcereview/resourceReview?id=' + id +'&status=-1',
					type: 'post',
					success: function (result) {
						if (result.code === 1 && result.url != '') {
							layer.msg('审核拒绝');
							setTimeout(() => {
								location.href = result.url
							}, 1000);
						}
					},
					error: function (xhr, state, errorThrown) {
						layer.msg(state + '：' + errorThrown);
					}
				});
			},function(index){
				layer.close(index);
				$.ajax({
					url: '/admin/resourcereview/resourceReview?id=' + id +'&status=1',
					type: 'post',
					success: function (result) {
						if (result.code === 1 && result.url != '') {
							layer.msg('审核通过');
							setTimeout(() => {
								location.href = result.url
							}, 1000);
							
						}
					},
					error: function (xhr, state, errorThrown) {
						layer.msg(state + '：' + errorThrown);
					}
				});
			});
	}
	
	function multiPush() {
		var userIds = [];
		$('.layui-table tbody input[lay-skin="primary"]:checked').each(function (i) {
			userIds[i] = $(this).val();
		});
		if (userIds === undefined || userIds.length == 0) {
			layer.msg('请选择数据');
			return false;
		}
		layer.open({
			type: 2,
			title: '消息',
			shadeClose: true,
			shade: false,
			area: ['860px', '600px'],
			content: '/admin/push/toPush?userId=' + userIds + '&template=4',
		});
	}
</script>
{/block}